<?php

/** 
 * @author acr
 * 
 */
class CLog {
	
	private $logDir;
	
	private static $instance;
	
	/**
	 */
	private function __construct() {
		$this->logDir = LOG_DIR;
	}
	
	public static function getInstance(){
		if(!self::$instance instanceof self){
			self::$instance = new self();
		}
		return self::$instance;
	}
	
	public function log($tag, $message){
		$entry = $this->now().' '.$tag.': '.$message."\n";
		file_put_contents($this->logFile(), $entry, FILE_APPEND);
	}
	
	private function logFile(){
		$dir = $this->logDir;
		$file = date('Y-m-d', time()).'.log';
		if(!file_exists($dir)){
			mkdir($dir, null, true);
		}
		return $dir.DS.$file;
	}
	
	public function getLogDir(){
		return $this->logDir;
	}
	private function now(){
		return date('Y-m-d H:i:s', time());
	}
	
}

?>